package com.dwd.hrm.config;


import com.dwd.hrm.handler.MyAuthenticationEntryPoint;
import com.dwd.hrm.handler.MyAuthenticationFailureHandler;
import com.dwd.hrm.handler.MyAuthenticationSuccessHandler;
import com.dwd.hrm.handler.MyDefaultAccessDeniedHandler;

import com.dwd.hrm.usedetail.MyUserDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImpl;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;

import javax.sql.DataSource;

/**
 * @Description: TODO
 * @Author 汶狄
 * @Date 2021/3/12 15:06
 * @Version 1.0
 */
@Configuration
@EnableWebSecurity//开启SpringSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private MyUserDetailsService myUserDetailsService;


    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/login", "/loginUser/login","/loginUser/refresh","/loginUser/save").permitAll()
                //其他路径都要拦截
                .anyRequest().authenticated()
                //允许表单登录
                .and().formLogin()
                //认证成功处理
                .and().csrf().disable();


    }


    @Bean
    @Override
    protected AuthenticationManager authenticationManager() throws Exception {
        return super.authenticationManager();
    }
}


